<template>
  <div>
    {{ articles }}
  </div>
</template>

<script>
export default {
  async asyncData({ $content, params }) {
    const articles = await $content('articles')
      .only(['title', 'description', 'img', 'slug', 'updatedAt'])
      .sortBy('createdAt', 'asc')
      .skip((params.num - 1) * 5)
      .limit(5)
      .fetch();

    if (articles.length === 0 || params.num === '1') {
      // eslint-disable-next-line no-throw-literal
      throw { statusCode: 404, message: 'Post not found' };
    }

    return {
      articles,
    };
  },
};
</script>
